# 把结构化jsonl数据转换为QA数据
import json
source='/home/lxy/wxbdata/教师信息改写整合.jsonl'

with open(source,'r',encoding='utf-8') as f:
    data=list(map(json.loads,f.readlines()))


# 这些模板的名字代表了他们的期望回答
templates = set([
"请告诉我有关东北大学的{teacher}的信息","我想了解一下东北大学的{teacher}","请提供一份有关{teacher}的简介","帮我介绍一下{teacher}",
"介绍一下{teacher}",
"{teacher}个人信息",
"提供一些关于{teacher}的背景信息",
"说说{teacher}",
"描述一下{teacher}？",
"{teacher}怎么样？",
'{teacher}是谁',
'介绍一下{teacher}','东北大学{teacher}','{teacher}',
'{school}{position}{teacher}',
'{school}{teacher}'
])

position_templates=set([
'{teacher}的职位是什么？',

])

with open('/home/lxy/wxbdata/db/全新的教师.jsonl','a',encoding='utf-8') as o:
    for d in data:
        teacher=d['name']
        description=d['description']
        position=d['position']
        school=d['school']
        for s in templates:
            question=s.format_map({'teacher':teacher,'position':position,'school':school})
            temp_dict={'question':question,'answer':description}
            json.dump(temp_dict,fp=o,ensure_ascii=False,allow_nan=False)
            o.write('\n')
        for s in position_templates:
            question=s.format_map({'teacher':teacher,'position':position,'school':school})
            temp_dict={'question':question,'answer':'截止2023年11月份,小助手了解的信息中'+teacher+'老师是'+position+'~'}
            json.dump(temp_dict,fp=o,ensure_ascii=False,allow_nan=False)
            o.write('\n')
